package com.ruoyi.business.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.TbCpadSale;
import com.ruoyi.business.service.ITbCpadSaleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务员信息Controller
 * 
 * @author ruoyi
 * @date 2024-07-17
 */
@RestController
@RequestMapping("/business/sale")
public class TbCpadSaleController extends BaseController
{
    @Autowired
    private ITbCpadSaleService tbCpadSaleService;

    /**
     * 查询业务员信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:sale:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCpadSale tbCpadSale)
    {
        startPage();
        List<TbCpadSale> list = tbCpadSaleService.selectTbCpadSaleList(tbCpadSale);
        return getDataTable(list);
    }

    /**
     * 导出业务员信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:sale:export')")
    @Log(title = "业务员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCpadSale tbCpadSale)
    {
        List<TbCpadSale> list = tbCpadSaleService.selectTbCpadSaleList(tbCpadSale);
        ExcelUtil<TbCpadSale> util = new ExcelUtil<TbCpadSale>(TbCpadSale.class);
        util.exportExcel(response, list, "业务员信息数据");
    }

    /**
     * 获取业务员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:sale:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCpadSaleService.selectTbCpadSaleById(id));
    }

    /**
     * 新增业务员信息
     */
    @PreAuthorize("@ss.hasPermi('business:sale:add')")
    @Log(title = "业务员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCpadSale tbCpadSale)
    {
        return toAjax(tbCpadSaleService.insertTbCpadSale(tbCpadSale));
    }

    /**
     * 修改业务员信息
     */
    @PreAuthorize("@ss.hasPermi('business:sale:edit')")
    @Log(title = "业务员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCpadSale tbCpadSale)
    {
        return toAjax(tbCpadSaleService.updateTbCpadSale(tbCpadSale));
    }

    /**
     * 删除业务员信息
     */
    @PreAuthorize("@ss.hasPermi('business:sale:remove')")
    @Log(title = "业务员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCpadSaleService.deleteTbCpadSaleByIds(ids));
    }
}
